package com.example.rocketmq.filter;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.concurrent.TimeUnit;

public class FilterProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("test_group");
        producer.setNamesrvAddr("192.168.228.103:9876");
        producer.start();
        for (int i=0; i<10; i++) {
            Message msg = new Message("filter_topic", "tag", String.format("hello world %s", i).getBytes());
            // 设置自定义的属性
            msg.putUserProperty("index", String.valueOf(i));
            SendResult result = producer.send(msg);
            System.out.println(result);
            TimeUnit.SECONDS.sleep(1);
        }
        producer.shutdown();
    }
}
